@extends('Admin.base')

@section('content')
    <div class="layui-card">
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <a class="layui-btn" href="{{ route('role.add') }}">添 加</a>
            </div>
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">

                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

            </script>
        </div>
    </div>
@endsection

@section('script')
        <script>
            layui.use(['layer','table','form','laytpl'],function () {
                var layer = layui.layer;
                var form = layui.form;
                var table = layui.table;
                //用户表格初始化
                var dataTable = table.render({
                    elem: '#dataTable'
                    //,height: 500
                    ,url: "{{ route('role.data') }}" //数据接口
                    ,page: true //开启分页
                    ,limit:30
                    ,cols: [[
                        {field: 'name', title: '角色名称'}
                        ,{field: 'model_has_adminer_count', title: '绑定用户数'}
                        ,{field: 'comment', title: '备注'}
                        ,{field: 'created_at', title: '创建时间'}
                        ,{fixed: 'right', title: '操作' , width: 200, align:'center', toolbar: '#options'}
                    ]]
                });

                //监听工具条
                table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data //获得当前行数据
                        ,layEvent = obj.event; //获得 lay-event 对应的值
                    if(layEvent === 'del'){
                        layer.confirm('确认删除吗？', function(index){
                            $.get("{{ route('role.destroy') }}",{id:[data.id]},function (result) {
                                if (result.code==1){
                                    obj.del(); //删除对应行（tr）的DOM结构
                                }
                                layer.close(index);
                                layer.msg(result.msg)
                            });
                        });
                    }else if(layEvent === 'edit'){
                        location.href = '/admin/role/edit?id='+data.id;

                    }
                });
            })




        </script>



@endsection






































